package com.system.boot.setting.converter;

import com.system.api.setting.entity.dto.IconFormDto;
import com.system.api.setting.entity.po.SysIcon;
import com.system.api.setting.entity.search.IconSearch;
import org.mapstruct.Mapper;
import org.mapstruct.Mapping;
import org.mapstruct.factory.Mappers;
import org.yang.database.orm.entity.BaseQuery;

import java.util.List;
import java.util.stream.Collectors;

/**
 * @author: lslands
 * @version: 1.0
 * @create: 2024/5/19
 * @description:
 */
@Mapper(builder = @org.mapstruct.Builder(disableBuilder = true),componentModel = "spring")
public interface IconConverter {
    IconConverter INSTANCE = Mappers.getMapper(IconConverter.class);

    /**
     * 转换 dtoForm -> po
     * @param formDto 插入对象
     * @return SysDict
     */
    @Mapping(target = "type", expression = "java(MapStruct.strToList(formDto.getType()))")
    SysIcon formEntity(IconFormDto formDto);

    /**
     * 转换 search -> BaseQuery
     * @param search 搜索对象转换
     * @return BaseQuery
     */
    BaseQuery queryEntity(IconSearch search);

    /**
     * 转换 search -> po
     * @param search 搜索对象转换
     * @return BaseQuery
     */
    @Mapping(target = "type", expression = "java(MapStruct.strToList(search.getType()))")
    SysIcon queryPoEntity(IconSearch search);


    class MapStruct {
        public static String strToList(List<Integer> brush) {
            if(!brush.isEmpty()){
                return brush.stream().map(Object::toString).collect(Collectors.joining(","));
            }
            return null;
        }
    }

}
